﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spanner;

namespace SpannerWebSite
{
    internal partial class RefRegExps : Reference
    {
        internal static SpannerChapter TheChapter;

        static RefRegExps()
        {
            var sections = new List<SpannerSection> { };
            var initActs = new List<Act> { };

            Action<string, string, Html> addSection = (title, id, html) =>
            {
                sections.Add(Section(Esc(title), id, html));
            };

            addSection("NewRegExp", "NewRegExp", P(Code("NewRegExp(pattern[, modifiers])"), " ",
                "denotes the JavaScript ", Code("new RegExp(pattern, modifiers)"), " (the modifiers parameter ",
                "is optional)."));

            addSection("Test", "Test", P(Code("Test(r, s)"), " denotes the JavaScript ",
                Code("r.test(s)"), "."));

            addSection("Exec", "Exec", P(Code("Exec(r, s)"), " denotes the JavaScript ",
                Code("r.exec(s)"), ", and returns a ", Code("RegExpMatch"), " value ",
                "which can be examined by the functions below."));

            addSection("MatchedSubstr", "MatchedSubstr", P(Code("MatchedSubstr(m)"), " denotes the ",
                "matched substring for ", Code("m"), ", the result of an ", Code("Exec"), "."));

            addSection("ParenMatches", "ParenMatches", P(Code("ParenMatches(m)"), " denotes the ",
                "array of matched substrings corresponding to parenthesized sub-patterns ",
                "for ", Code("m"), ", the result of an ", Code("Exec"), "."));

            addSection("ParenMatch", "ParenMatch", P(Code("ParenMatch(m, i)"), " denotes the ",
                "ith matched substrings corresponding to parenthesized sub-patterns ",
                "for ", Code("m"), ", the result of an ", Code("Exec"), "."));

            addSection("MatchIndex", "MatchIndex", P(Code("MatchIndex(m)"), " denotes the ",
                "start index of the matched substring for ", Code("m"), ", the result of an ", Code("Exec"), "."));

            addSection("MatchInput", "MatchInput", P(Code("MatchInput(m)"), " denotes the ",
                "match input for ", Code("m"), ", the result of an ", Code("Exec"), "."));

            TheChapter = CommonUI.Chapter("Reference - Regular Expressions", "RefRegExps", sections, initActs);
        }
    }
}
